package com.mdd.admin.controller.bill;

import com.alipay.api.AlipayApiException;
import com.mdd.admin.service.bill.IOrderBillPayService;
import com.mdd.admin.service.bill.OrderBillInfoService;
import com.mdd.admin.validate.bill.AuditOrderBillValidate;
import com.mdd.admin.validate.bill.OrderBillInfoSearchValidate;
import com.mdd.admin.validate.bill.OrderBillInfoValidate;
import com.mdd.common.aop.CurrentUser;
import com.mdd.common.aop.Log;
import com.mdd.common.aop.NotPower;
import com.mdd.common.base.page.PageValidate;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.entity.OrderBillInfo;
import com.mdd.common.validate.IdValidate;
import com.mdd.system.vo.SystemAuthAdminInformVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("api/orderBillPay")
@Api(tags = "账单管理")
public class OrderBillPayController {

    @Resource
    IOrderBillPayService orderBillPayService;
    @Resource
    OrderBillInfoService orderBillInfoService;

    @NotPower
    @PostMapping("/execOrderBill")
    @ApiOperation(value = "执行待扣款账单")
    public AjaxResult<Object> execOrderBill(@Validated @RequestBody IdValidate idValidate) {
        OrderBillInfo orderBillInfo = orderBillInfoService.getById(idValidate.getId());
        orderBillPayService.execOrderBill(orderBillInfo);
        return AjaxResult.success();
    }
    @NotPower
    @GetMapping("/billList")
    @ApiOperation(value = "全部账单列表")
    public AjaxResult<Object> billList(@Validated PageValidate pageValidate, @Validated  OrderBillInfoSearchValidate orderBillInfoSearchValidate, @CurrentUser SystemAuthAdminInformVo systemAuthAdmin) {
        PageResult<OrderBillInfo> list = orderBillInfoService.list(pageValidate,orderBillInfoSearchValidate,systemAuthAdmin);
        return AjaxResult.success(list);
    }
    @NotPower
    @GetMapping("/orderBillList")
    @ApiOperation(value = "账单列表 （订单详情）")
    public AjaxResult<Object> orderBillList(@Validated  PageValidate pageValidate,  @Validated  OrderBillInfoSearchValidate orderBillInfoSearchValidate, @CurrentUser SystemAuthAdminInformVo systemAuthAdmin) {
        PageResult<OrderBillInfo> list = orderBillInfoService.list(pageValidate,orderBillInfoSearchValidate,systemAuthAdmin);
        return AjaxResult.success(list);
    }
    @NotPower
    @PostMapping("/auditBill")
    @ApiOperation(value = "审核账单")
    public AjaxResult<Object> auditBill(@Validated @RequestBody AuditOrderBillValidate auditOrderBillValidate) throws AlipayApiException {
        orderBillPayService.auditBill(auditOrderBillValidate);
        return AjaxResult.success();
    }

    @NotPower
    @Log(title = "新增扣款账单")
    @PostMapping("/addPenaltyBill")
    @ApiOperation(value = "订单新增违章账单")
    public AjaxResult<Object> addPenaltyBill(@Validated @RequestBody OrderBillInfoValidate orderBillInfoValidate) {
        orderBillPayService.addPenaltyBill(orderBillInfoValidate);
        return AjaxResult.success();
    }
}
